package com.me.modules.report.controller;

import com.me.modules.common.controller.BaseController;
import com.me.modules.common.utils.JsonUtil;
import com.me.modules.report.service.AffReportService;
import com.me.modules.sys.entity.CodeEntity;
import com.me.modules.sys.service.CodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;


/**
 * 事件报表
 *
 * @author lill
 * @email lill5270@163.com
 * @date 2019-01-16 17:20:30
 */
@Controller
@RequestMapping("/report/affreport")
public class AffReportController extends BaseController{
	@Autowired
	private AffReportService affReportService;
	@Autowired
	private CodeService codeService;


	/**
	 * 列表
	 */
	@RequestMapping("/AffClosePie")
//	@RequiresPermissions("srminfo:list")
//	@SysLog("查询变更列表")
	public String AffClosePie(@RequestParam Map<String, Object> params, Model model , HttpServletRequest request){
		List<Object> list =affReportService.AffClosePie(params);
		model.addAttribute("params",params);
		model.addAttribute("data",JsonUtil.getJsonByObj(list));
		return "report/affairs/AffClosePie";
	}

	/**
	 * 列表
	 */
	@RequestMapping("/AffOrignPie")
//	@RequiresPermissions("srminfo:list")
//	@SysLog("查询变更列表")
	public String AffOrignPie(@RequestParam Map<String, Object> params, Model model , HttpServletRequest request){
		List<Object> list =affReportService.AffOrignPie(params);
		model.addAttribute("params",params);
		model.addAttribute("data",JsonUtil.getJsonByObj(list));
		return "report/affairs/AffOrignPie";
	}

	/**
	 * 列表
	 */
	@RequestMapping("/AffTypePie")
//	@RequiresPermissions("srminfo:list")
//	@SysLog("查询变更列表")
	public String AffTypePie(@RequestParam Map<String, Object> params, Model model , HttpServletRequest request){
		List<Object> list =affReportService.AffTypePie(params);
		model.addAttribute("params",params);
		model.addAttribute("data",JsonUtil.getJsonByObj(list));
		return "report/affairs/AffTypePie";
	}
	/**
	 * 列表
	 */
	@RequestMapping("/AffLineOrginMonth")
//	@RequiresPermissions("srminfo:list")
//	@SysLog("查询变更列表")
	public String AffLineOrginMonth(@RequestParam Map<String, Object> params, Model model , HttpServletRequest request){
		List list =new ArrayList();
		List<CodeEntity> codeList  =codeService.queryChildsByMark("aff_type");
		list.add(codeList);
		Date endDate= (Date) params.get("endDate");
		if(endDate==null){
			params.put("endDate",new Date());
		}
		List listColumn = new ArrayList();
		for (CodeEntity code :codeList) {
			params.put("aff_type",code.getValue());
			List<Object> month =affReportService.AffLineOrginMonth(params);
			listColumn.add(month);
		}
		list.add(listColumn);
		model.addAttribute("params",params);
		model.addAttribute("data",JsonUtil.getJsonByObj(list));
		return "report/affairs/AffLineOrginMonth";
	}


	/**
	 * 列表
	 */
	@RequestMapping("/AffLineMonthNumber")
//	@RequiresPermissions("srminfo:list")
//	@SysLog("查询变更列表")
	public String AffLineMonthNumber(@RequestParam Map<String, Object> params, Model model , HttpServletRequest request){
		Date endDate= (Date) params.get("endDate");
		if(endDate==null){
			params.put("endDate",new  Date());
		}
		List<Object> list =affReportService.AffLineMonthNumber(params);
		model.addAttribute("params",params);
		model.addAttribute("data",JsonUtil.getJsonByObj(list));
		return "report/affairs/AffLineMonthNumber";
	}






}
